package ch12.process;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Scanner;

public class ReadDir {
    public static void main(String[] args) throws IOException, InterruptedException {
        // 如果要运行dir，则需要"cmd.exe", "/C", "dir"
        var p = new ProcessBuilder("C:\\Program Files\\Git\\usr\\bin\\ls.exe", "-l")
            .directory(Path.of("ch12").toFile())    // 工作目录
            .start();
        // 读取进程的输出流
        try (var in = new Scanner(p.getInputStream())) {
            while (in.hasNext()) {
                System.out.println(in.nextLine());
            }
        }
        int result = p.waitFor();
        System.out.println("Exit code: " + result);
    }
}
